<?php
/**
 * @package     LKVSolutions.cDomain
 * @subpackage  mod_checkdomain
 * @
 * @copyright   Copyright (C) 2014 - 2015 LKV Solution Team, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
defined('_JEXEC') or die;

jimport( 'joomla.plugin.plugin' );

class plgSystemVietAlias extends JPlugin
{
	var $layout = '';
	var $option = '';
	
	function __construct(& $subject, $config)
	{
		parent::__construct($subject, $config);
	
		$this->layout = JRequest::getCmd('layout');
		$this->option = JRequest::getCmd('option');
	
		if ( $this->layout != 'edit') return;
	
		$active = (bool) $this->params->get('active_on');
		$pages	= $this->params->get('active_on_specific');
	
		if( $active || (strpos($pages, $this->option) !== false) )
		{
			require_once __DIR__ . '/output.php';
		}
	
	}
	
	function onAfterDispatch()
	{
	
		if ( $this->layout != 'edit') return false;
		
		$auto_complete	= (bool) $this->params->get('auto_complete');
		$pages			= $this->params->get('auto_complete_on_specific');
		
		if( $auto_complete || (strpos($pages, $this->option) !== false) )
		{
			$doc = JFactory::getDocument();
			$doc->addScript( rtrim(JURI::root( true ), '/').'/media/plg_system_vietalias/js/vietalias.js' );
		}
		return true;
	}
}